package com.example.llollama.util;

import com.example.llollama.user.ChatContext;
import org.springframework.ai.document.Document;

import java.util.List;
import java.util.Map;

public class PromptUtil {
    public static String buildPromptWithContext(ChatContext context, String userMessage) {
        StringBuilder promptBuilder = new StringBuilder();

        for (String message : context.getMessages()) {
            promptBuilder.append(message).append("\n");
        }

        promptBuilder.append("user: ").append(userMessage).append("\n");
        promptBuilder.append("assistant: ");
        return promptBuilder.toString();
    }
    public static void setSource(List<Document> list,String filePath){
         list.stream().map(e -> {
            Map<String, Object> metadata = e.getMetadata();
            metadata.put("filePath", filePath);
            return new Document(e.getContent(), metadata);
        }).toList();
    }
}
